﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using Nissen_Model;

namespace Nissen_Dao
{
	public class RecordDataDao :DaoBase
	{
		public void SaveOrUpdateRecordDatas(IList<RecordData> recordDatas)
		{
            //using (ISession session = this.SessionFactory.OpenSession())
            //{
            //    foreach (var recordData in recordDatas)
            //    {
            //        ICriteria crt = session.CreateCriteria<RecordData>();
            //        crt.Add(Restrictions.Eq("QuestionNo", recordData.QuestionNo));
            //        crt.Add(Restrictions.Eq("NissenSSO", recordData.NissenSSO));
            //        IList<RecordData> tempRecords = crt.List<RecordData>();

            //        if (tempRecords.Count > 0)
            //        {
            //            var tempRecord = tempRecords[0];
            //            tempRecord.QuestionResult = recordData.QuestionResult;
            //            tempRecord.EndWorkDate = recordData.EndWorkDate;
            //            session.SaveOrUpdate(tempRecord);
            //        }
            //        else
            //        {
            //            session.SaveOrUpdate(recordData);
            //            //Session.SaveOrUpdate()
            //        }
            //    }
            //}
            //    return;
			using (ISession session = this.SessionFactory.OpenSession())
			{
				using (ITransaction t1 = session.BeginTransaction())
				{

					foreach (var recordData in recordDatas)
					{
                        //ICriteria crt = session.CreateCriteria<RecordData>();
                        //crt.Add(Restrictions.Eq("QuestionNo", recordData.QuestionNo));
                        //crt.Add(Restrictions.Eq("NissenSSO", recordData.NissenSSO));
                        //IList<RecordData> tempRecords = crt.List<RecordData>();

						if(false)//tempRecords.Count>0)
						{
							//var tempRecord = tempRecords[0];
                            //tempRecord.QuestionResult = recordData.QuestionResult;
                            //tempRecord.EndWorkDate = recordData.EndWorkDate;
                            //session.SaveOrUpdate(tempRecord);
						}
						else
						{
							session.SaveOrUpdate(recordData);
						}
					}
					
					t1.Commit();
				}
			}
		}
	}
}
